<template>
  <div class="main">
    <img src="../assets/image/login.png" alt="" class="leftImg" />
    <div class="rightBox">
      <div class="title">登录</div>
      <div class="label">账号</div>
      <el-input v-model="formData.cell" />
      <div class="label">密码</div>
      <div>
        <el-input type="password" v-model="formData.loginPwd" show-password />
      </div>
      <el-button class="btn" type="primary" @click="submitForm"> 登录 </el-button>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { getInfo } from '../api/home'
import router from '../router'
import { ElMessage } from 'element-plus'

const formData = ref({
  cell: '',
  loginPwd: ''
})
const commonFn = (data: any) => {
  return {
    FormId: 'BD_NEWSTAFF',
    Data: {
      FieldKeys: 'FSTAFFID,FName,FNumber,FOperatorType,FPMobile,F_TEZV_MM',
      FilterString: data,
      OrderString: '',
      TopRowCount: 0,
      StartRow: 0,
      Limit: 2000,
      SubSystemId: '',
      FormId: 'BD_NEWSTAFF'
    }
  }
}
const submitForm = async () => {
  const res: any = await getInfo(
    commonFn([
      {
        Left: '(',
        FieldName: 'FPMobile',
        Compare: '=',
        Value: formData.value.cell,
        Right: ')',
        Logic: 'AND'
      },
      {
        Left: '(',
        FieldName: 'FDept.fname',
        Compare: '=',
        Value: '仓储部',
        Right: ')',
        Logic: 'AND'
      }
    ])
  )
  if (res.length === 0) {
    ElMessage({
      message: '账号不存在！',
      type: 'error'
    })
    return
  }
  const res2: any = await getInfo(
    commonFn([
      {
        Left: '(',
        FieldName: 'FPMobile',
        Compare: '=',
        Value: formData.value.cell,
        Right: ')',
        Logic: 'AND'
      },
      {
        Left: '(',
        FieldName: 'F_TEZV_MM',
        Compare: '=',
        Value: formData.value.loginPwd,
        Right: ')',
        Logic: 'AND'
      },
      {
        Left: '(',
        FieldName: 'FDept.fname',
        Compare: '=',
        Value: '仓储部',
        Right: ')',
        Logic: 'AND'
      }
    ])
  )
  if (res2.length === 0) {
    ElMessage({
      message: '密码错误',
      type: 'error'
    })
    return
  }
  const arr: any[] = []
  res.forEach((item: string[]) => {
    let obj = {
      FName: item[0],
      FNumber: item[1],
      FCompany: item[2],
      FCompanyType: item[3],
      FMobile: item[4],
      FBizLocation: item[5],
      FBizLocNumber: item[6],
      F_TEZV_KEY: item[7]
    }
    arr.push(obj)
  })
  ElMessage({
    message: '登录成功',
    type: 'success'
  })
  sessionStorage.setItem('userInfo', JSON.stringify(arr))
  router.push('/')
}
</script>

<style scoped lang="less">
.main {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
}
.leftImg {
  width: 50%;
  height: 100%;
}
.rightBox {
  width: 50%;
  height: 100%;
  padding: 205px 200px;
  .title {
    font-size: 28px;
    font-weight: 600;
    color: #171721;
    margin-bottom: 61px;
  }
  .label {
    font-size: 18px;
    color: #171721;
    line-height: 25px;
    margin: 10px 0;
  }
  :deep(.el-input) {
    width: 520px !important;
  }
  :deep(.el-input__wrapper) {
    background: #f5f9fe !important;
    height: 48px;
    border-radius: 8px;
  }
  .btn {
    width: 520px;
    height: 48px;
    background: #3e7eff;
    border-radius: 8px;
    margin-top: 60px;
  }
}
</style>
